#include <algorithm>
#include <iostream>
#include <vector>

const int MAXN = 1e5+5;
const int bit = 31;
std::vector<std::pair<int, int>> adj[MAXN];
int dist[MAXN];

namespace t {
    int t[MAXN * bit][2];
    int nodec;

    void init() {
        t[0][0] = t[0][1] = 0;
        nodec = 1;
    }

    void insert(int val) {
        int curnode = 0;
        for (int i = bit - 1; i >= 0; --i) {
            int bit = (val >> i) & 1;
            if (!t[curnode][bit]) {
                t[nodec][0] = t[nodec][1] = 0;
                t[curnode][bit] = nodec++;
            }
            curnode = t[curnode][bit];
        }
    }

    int qmaxor(int val) {
        int curnode = 0;
        int maxorval = 0;
        for (int i = bit - 1; i >= 0; --i) {
            int bit = (val >> i) & 1;

            if (t[curnode][!bit]) {
                maxorval |= (1 << i);
                curnode = t[curnode][!bit];
            } else {

                curnode = t[curnode][bit];
            }
        }
        return maxorval;
    }
}

void dfs(int u, int p, int curxorsum) {
    dist[u] = curxorsum;
    for (auto &edge : adj[u]) {
        int v = edge.first;
        int weight = edge.second;
        if (v == p) {
            continue;
        }
        dfs(v, u, curxorsum ^ weight);
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;

    for (int i = 0; i < n - 1; ++i) {
        int u, v, w;
        std::cin >> u >> v >> w;

        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
    }

    dfs(1, 0, 0);

    t::init();
    for (int i = 1; i <= n; ++i) {
        t::insert(dist[i]);
    }

    int max_ans = 0;
    for (int i = 1; i <= n; ++i) {
        max_ans = std::max(max_ans, t::qmaxor(dist[i]));
    }

    std::cout << max_ans << '\n';

    return 0;
}
